package com.swm.julie.rest.crud.twitt.delete;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteTwittServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub

		//Delete the twitts with the id
		DeleteTwitt deleter = new DeleteTwitt();
		deleter.setIndexDir(System.getProperty("user.dir") + "/tempNewTwitt");
		if(deleter.delete(req.getParameter("id")))
		{
			req.setAttribute("delete", true);
		}else
		{
			req.setAttribute("delete", false);
		}
		
		//Dispatch to the view page
		System.out.println("DeleteTwittServlet.doGet() : Dispatch to searchResult.jsp");
		RequestDispatcher view = req.getRequestDispatcher("deleteResult.jsp");
		view.forward(req, resp);
		
	}
	
}
